in_kubernetes_events: fix OOB reads from non-NUL-terminated msgpack strings - #12180
in_kubernetes_events: fix OOB reads from non-NUL-terminated msgpack strings#12180zanarellidev wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughKubernetes event MessagePack parsing now enforces exact field-name lengths. Timestamp and numeric strings use bounded buffers and strict validation. Negative integers are rejected, and malformed timestamps can fall through to later candidates. ChangesKubernetes event parsing
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@plugins/in_kubernetes_events/kubernetes_events.c`:
- Around line 250-251: Update item_get_timestamp() to treat
record_get_field_time() results other than 0 as failures, including -2 for empty
or oversized timestamp values. Ensure each lastTimestamp, firstTimestamp, and
metadata.creationTimestamp path only returns success when ret == 0, allowing
fallback timestamps to be attempted after malformed values.
- Line 256: Update the timestamp parsing around flb_strptime() to capture its
returned end pointer and require both successful parsing and *end == '\0'. Apply
this validation consistently to lastTimestamp, firstTimestamp, and
metadata.creationTimestamp so trailing characters are rejected.
- Around line 287-295: Update record_get_field_uint64() to parse the copied
string with an explicit unsigned, digits-only conversion instead of accepting
strtoul’s signed or overflowing results. Clear errno before conversion, reject
any non-digit input including signs, reject ERANGE and values exceeding
UINT64_MAX, and preserve the existing invalid-field return behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: df686c53-d865-4bd7-8b94-188fa68f3a35
📒 Files selected for processing (1)
plugins/in_kubernetes_events/kubernetes_events.c
…trings record_get_field_uint64() and record_get_field_time() called strtoul()/flb_strptime() directly on msgpack_object.via.str.ptr. msgpack strings are raw, length-prefixed bytes into the decode buffer, not NUL-terminated, so these C-string functions could read past the field's true boundary. record_get_field_ptr()'s strncmp() key match had the same latent issue (a key that is a prefix of fieldname could false-match, and a short key could still be read past its bounds by strncmp with a longer fieldname length). A spec-compliant Kubernetes Event field (e.g. resourceVersion as a digit-only JSON string) placed at the edge of the decode buffer is enough to trigger an out-of-bounds read; confirmed via a guard-page harness that reproduces EXC_BAD_ACCESS inside strtoul_l, called from record_get_field_uint64. This is the same bug class fixed same-day for the sibling out_stackdriver plugin (fluent#12022, backported in fluent#12170), and the same class that produced GHSA-5rjf-prwh-pp7q in this project before. Applies the same fix pattern here: copy the field into a bounded, NUL-terminated stack buffer before parsing, and require an exact length match before the key strncmp. A prior contributor flagged the same underlying issue in fluent#12073, but it was self-closed without a fix landing; the vulnerable code is still present at HEAD. Signed-off-by: zanarelli <zanarelli.dev@gmail.com>
Require flb_strptime to consume the full copied buffer, treat only ret==0 as a successful timestamp in item_get_timestamp(), and parse uint64 strings with strtoull+errno so malformed or overflowing values fall through to the next timestamp field instead of being accepted. Signed-off-by: Raphael Zanarelli <zanarelli.dev@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com> Signed-off-by: zanarelli <zanarelli.dev@gmail.com>
da330b9 to
9ff6672
Compare
Summary
record_get_field_uint64()andrecord_get_field_time()inplugins/in_kubernetes_events/kubernetes_events.ccallstrtoul()/flb_strptime()directly onmsgpack_object.via.str.ptr. msgpack strings are raw, length-prefixed bytes pointing directly into the decode buffer — they are not NUL-terminated — so these C-string functions can read past the field's true boundary.record_get_field_ptr()'s key match viastrncmp(k->via.str.ptr, fieldname, strlen(fieldname))had the same class of issue: no exact-length check, so a key that's a prefix offieldnamecould false-match, and comparison length wasn't bounded by the key's own size.A spec-compliant Kubernetes Event field (e.g.
resourceVersionas a digit-only JSON string, per the Kubernetes API docs) placed near the edge of the decode buffer is enough to trigger an out-of-bounds read. Reproduced locally with a harness that calls the realflb_pack_json()on{"resourceVersion":"999999"}, places the resulting buffer against aPROT_NONEguard page, and calls the real (recompiled) plugin function on it — confirmed vialldb:EXC_BAD_ACCESSinsidestrtoul_l, called fromrecord_get_field_uint64at the line doing the unboundedstrtoulcall.This is the same bug class fixed same-day for the sibling
out_stackdriverplugin (#12022, backported in #12170), and the same class that produced a real CVE in this project before (GHSA-5rjf-prwh-pp7q).A prior contributor flagged the same underlying issue in #12073 but self-closed it without a fix landing; the vulnerable code is still present at HEAD. Filing this with a fix and full explanation/repro so it doesn't fall through again.
Fix
Same pattern the maintainers already established for the sibling
out_stackdriverfix: copy the field into a bounded, NUL-terminated stack buffer before parsing (strtoul,flb_strptime), and require an exact length match before the keystrncmp.Test plan
ctestsuite (90 tests) passes clean after the fix.in_kubernetes_eventsruntime test suite (flb-rt-in_kubernetes_events) passes clean after the fix.lldb-confirmedEXC_BAD_ACCESSinstrtoul_l); same harness runs clean (resource_version=999999, exit 0) after the fix.Happy to share the repro harness if useful for a permanent regression test — it needs an
mmap'd guard page, which doesn't fit cleanly into the existing runtime-test infra (same constraint the maintainers' own #12022 fix had, which also didn't add a crash-reproducing test).Summary by CodeRabbit